package com.neuedu.shixun.hospital2.controller;

import com.neuedu.shixun.hospital2.entity.Doctor;
import com.neuedu.shixun.hospital2.entity.Doctor2;
import com.neuedu.shixun.hospital2.service.DoctorService;
import com.neuedu.shixun.hospital2.util.MD5Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/doctor")
@CrossOrigin
public class DoctorController {
    @Autowired
    private DoctorService doctorService;
    @GetMapping("getDoctor")
    public List<Doctor2> getDoctor(){
        List<Doctor> list=doctorService.getDoctor();
        log.info("list"+list);
        List<Doctor2> list1=doctorService.getDoctor2(list);
        log.info("list"+list1);
       return list1;
    }
    @GetMapping("getOne")
    public Doctor2 getOne( String jobNum){
//        log.info("jjjjjjj"+jobNum);
        Doctor doctor=doctorService.getOne(jobNum);
        log.info("测试doctor："+doctor);

        Doctor2 doctor2=doctorService.getOne2(doctor);
        log.info("测试doctor2："+doctor2);
        return doctor2;
    }
    @PostMapping("JiaMi")
    public String Jiami(@RequestBody String pass){
       return doctorService.Jiami(pass);
    }
    @PostMapping(value ={"updateDoctor","saveDoctor"})
    public Doctor save(@RequestBody Doctor doctor){
        log.info("要修改的doctor:"+doctor);
        try {
            doctor.setDPassword(MD5Util.EncoderByMd5(doctor.getDPassword()));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Doctor doctor1= doctorService.update(doctor);
        log.info("doctor1:"+doctor1);
        return doctor1;
    }
}
